package com.ns002.yigou.quote.dao;

import com.ns002.yigou.quote.entity.KLine;
import com.ns002.yigou.quote.entity.Tuser;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @Author xu
 * @Date 2017/7/27 0027 下午 2:19
 * K线数据操作
 */
@Repository
public interface KLineDao extends PagingAndSortingRepository<KLine, Integer>, JpaSpecificationExecutor<Tuser> {

    /**
     * 查询一分钟K线
     * @param contract
     * @param start
     * @param end
     * @return
     */
    @Query(value = "SELECT * FROM mk_kline WHERE contract=:contract AND type=1 AND start_date BETWEEN :start AND :end ORDER BY quote_date",
    nativeQuery = true)
    List<KLine> findKlineM1(@Param("contract") String contract,@Param("start")  Date start,@Param("end")  Date end);

    /**
     * 查询K线信息
     * @param contract
     * @param type
     * @return
     */
    @Query(value = "SELECT * FROM mk_kline WHERE contract=:contract AND type=:type ORDER BY start_date DESC LIMIT 400",
            nativeQuery = true)
    List<KLine> findkline(@Param("contract") String contract,@Param("type")  Integer type);
}
